package com.jz.community.moduleshoppingguide.nearshop.ui.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.bean.baseGoods.BaseGoodsInfo;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshoppingguide.R;
import com.jz.community.moduleshoppingguide.nearshop.utils.SpaceItemDecoration;

import java.util.ArrayList;
import java.util.List;

public class StandardAdapter extends BaseQuickAdapter<BaseGoodsInfo.EmbeddedBeanXX.ContentBeanX.SkuPropertiesBean, BaseViewHolder> {


    private IChooseStandard cstandard;

    public StandardAdapter(int layoutResId, @Nullable List<BaseGoodsInfo.EmbeddedBeanXX.ContentBeanX.SkuPropertiesBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, BaseGoodsInfo.EmbeddedBeanXX.ContentBeanX.SkuPropertiesBean item) {
        TextView textView = helper.getView(R.id.tv_sku_title);
        textView.setText(item.getName());
        RecyclerView rv = helper.getView(R.id.rv_sku);
        rv.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.HORIZONTAL, false));
        rv.addItemDecoration(new SpaceItemDecoration(SHelper.dp2px(mContext, 7)));
        StandardItemAdapter standardItemAdapter = new StandardItemAdapter(R.layout.module_shoppingguide_flow_item, new ArrayList<>(), item);
        rv.setAdapter(standardItemAdapter);
        standardItemAdapter.setNewData(item.getPropertyValues());
        standardItemAdapter.setIchoose(() -> {
            if (cstandard != null) {
                cstandard.chooseStandard();
            }
        });
    }

    public interface IChooseStandard {
        void chooseStandard();
    }

    public void setCstandard(IChooseStandard cstandard) {
        this.cstandard = cstandard;
    }
}
